#include "xmlitem.h"

#include <QHash>

const QString XMLItem::KEY_DESCRIPTION = "description";
const QString XMLItem::KEY_NAME = "name";

XMLItem::XMLItem()
  : _isValid(false) {
}

XMLItem::XMLItem(const QMap<QString, QString> &values)
  : _isValid(true)
{
    Q_ASSERT(values.contains(XMLItem::KEY_DESCRIPTION));
    Q_ASSERT(values.contains(XMLItem::KEY_NAME));

    _description = values[XMLItem::KEY_DESCRIPTION];
    _name = values[XMLItem::KEY_NAME];
}

XMLItem::~XMLItem()
{
}

QString XMLItem::keyValue(const QString &key) const
{
    if (key == KEY_NAME) return name();
    else if (key == KEY_DESCRIPTION) return description();

    return "";
}

bool XMLItem::operator==(const XMLItem &other) const
{
  return _name == other._name;
}

bool XMLItem::operator<(const XMLItem &other) const
{
  return name() < other.name();
}

XMLItem::operator QString() const
{
    return _name;
}

uint qHash(const XMLItem &item)
{
  return qHash(item.name());
}
